# encoding: utf-8


"""

@author: tongzhenguo

@time: 2020/12/21 下午2:02

@desc:


"""
import traceback

import requests


# 封装接口交互,返回json的dict
def get(host, uri, params):
    url = "http://{host}{uri}{params}".format(host=host, uri=uri, params=params if params else "")
    # 无需urlencode  url = urlencode(url)
    try:
        res = requests.get(url).json()
        return res
    except Exception as e:
        print('url : %s , error : %s' % (url, repr(e)))
        traceback.print_exc()


# 封装接口交互,返回json的dict
def post(host, uri, headers, data, params):
    assert type(headers) == dict
    assert type(data) == str
    url = "http://{host}{uri}{params}".format(host=host, uri=uri, params=params if params else "")
    # url = urlencode(url)
    try:
        if headers:
            # print(url, data)
            res = requests.post(url, data, headers=headers).json()
            return res
        else:
            res = requests.post(url, data).json()
            # print(url, data)
            return res
    except Exception as e:
        print('url : %s , error : %s' % (url, repr(e)))
        traceback.print_exc()


if __name__ == "__main__":
    pass
